<html>
<head> 
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="TEXT/HTML; CHARSET=iso-8859-8-i">
<link href="css/sty.css" rel="stylesheet" type="text/css" media="screen" />
<center>
<?php
if (!$_GET['nolinks']) {
?>
<a href="default.php?fname=postmsg" target="_self">Post a new message</a>
<?php
}
?>
</center>
<pre class=strict>
<style type="text/css">
p { margin: 0; padding: 0; }
</style>
<?php

$serv = 'enter server here';
$user = 'enter user name here';
$pass = 'enter password here';
$dbase = 'entere database name here';

$link = mysql_connect($serv,$user,$pass);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

if (!mysql_select_db($dbase, $link)) {
    echo 'Error : Could not select database\n';
    exit;
}


if ($_POST['elm2'])
{
date_default_timezone_set('Israel'); 
$now = getdate();
$nowtime = $now['hours'] . ':' . $now['minutes'] . ':' . $now['seconds'];
$nowdate = $now['year'] .'.'. $now['mon'] .'.'. $now['mday'];
//$sql    = 'INSERT INTO guestbook (\'index\' ,\'data\' ,\'author\' ,\'date\' ,\'time\') VALUES (\'456\', \''. $_POST['elm2'] . '\', \'' . $_POST['user'] . ', \'30/4/10\', \'17:42\')';
	$sql = 'INSERT INTO guestbook (data ,author ,date ,time) VALUES (\'' . $_POST['elm2'] . '\', \''.$_POST['user'].'\', \''. $nowdate .'\',\'' . $nowtime . '\')';
	//echo $sql;
	$result = mysql_query($sql, $link);

	if (!$result) {
		echo "error\n";
		echo $result;
		exit;
		} else
		echo "done...\n";
}

	/*
	echo '1';
$link = mysql_connect($serv,$user,$pass);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo '2';
if (!mysql_select_db($dbase, $link)) {
    echo 'Error : Could not select database\n';
    exit;
}
*/
$sql = 'SELECT max(`index`) from guestbook';
//echo $sql;
$result = mysql_query($sql, $link);

if (!$result) {
    echo "error while posting message\n";	
	exit;
	} else
	//echo "done...\n";

$max = mysql_fetch_assoc($result);
$max = $max['max(`index`)'];

//echo $max;
$start = $max - ($_GET['show'] * ($_GET['id'] + 1)) + 1;
$end = $_GET['show'] + $start - 1;

//echo "start.".$start;
//echo "end.".$end;
if ($_GET['rid']) {
	$start = $_GET['rid'];
	$end = $start + $_GET['show'] - 1;
}

$sql = 'SELECT * from guestbook where (`index` BETWEEN '  . $start . ' AND ' . $end . ') ORDER BY `index` DESC';
//echo $sql;
$result = mysql_query($sql, $link);

if (!$result) {
    echo "error querying guestbook database\n";
	exit;
	} else
	//echo "done...\n";

do {

	$row = mysql_fetch_assoc($result);
	
	if (!$row)
		break;
	
	echo "<div class=guestmsg> from: " . $row['author'] . "<br/> date: " . $row['date'] . "<br/> time:" . $row['time'] . "<br/><hr/><div class=guestdat>". $row['data'] ."</div></div>";
		

} while ($row);

if (!$_GET['nolinks'])	
{
$navigate = 10;
$idx = 0;
while ($idx < $max / $_GET['show'])
{
	$id = $_GET['id'];
	if ($idx < $id - $navigate)
	{
		echo "<a href=\"default.php?fname=guestbook&id=0&show=".$_GET['show']."\" target=\"_self\"><<</a>";
		$idx = $id - $navigate + 1;
		continue;
	}
		
	if ($idx > $id + $navigate)
	{
		echo "<a href=\"default.php?fname=guestbook&id=".$idx."&show=".$_GET['show']."\" target=\"_self\">...</a>";
		break;
	}
		
	if ($idx == $_GET['id'])
		echo "<b class=currentidx>";		
	echo "<a href=\"default.php?fname=guestbook&id=".$idx."&show=".$_GET['show']."\" target=\"_self\">".$idx."</a>";
	if ($idx == $_GET['id'])
		echo "</b>";
		
	
	$idx++;
}	
}
?>
</pre>
</html>